package com.iemes.controller.order;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.controller.index.BaseController;
import com.iemes.entity.ClientFormMap;
import com.iemes.entity.OrderFormMap;
import com.iemes.entity.OrderperFormMap;
import com.iemes.entity.UserFormMap;
import com.iemes.mapper.UserMapper;
import com.iemes.mapper.client.ClientMapper;
import com.iemes.mapper.order.OrderpreMapper;
import com.iemes.plugin.PageView;
import com.iemes.service.OrderService;
import com.iemes.util.Common;
import com.iemes.util.PublicUtils;

@RequestMapping("/orderthrough/")
@Controller
public class OrderThroughController extends BaseController{

	@Inject
	private ClientMapper clientMapper;
	@Inject
	private OrderService orderService;
	@Inject
	private OrderpreMapper orderpreMapper;
	@Inject
	private UserMapper userMapper;
	//查看订单
	@RequestMapping("walkthrough")
	public String examineOrder(Model model){
		//获取所有客户
		List<ClientFormMap> clientFormMap=clientMapper.findByWhere(new ClientFormMap());
		model.addAttribute("client", clientFormMap);
		List<UserFormMap> userFormMaps=userMapper.findByWhere(new UserFormMap());
		model.addAttribute("alluser", userFormMaps);
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/order/orderthrough/order_through_list";
	}
	
	@Transactional(readOnly=false)
	public  void walkthrough(){
		List<Map<String, Object>> orderFormMap=orderService.worktuough(getFormMap(OrderFormMap.class));
		//获取预排数据保存于数据库
		try {
			orderService.getOrderpre(orderFormMap);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
		//预排分页，默认7天
		@ResponseBody
		@RequestMapping("walkthrough_findByPage")
		@Transactional(readOnly=false)
		public PageView findByPage(String pageNow, String pageSize) throws Exception 
		{	
			PublicUtils.Walkthrough_days=7;
			walkthrough();
			OrderperFormMap orderperFormMap=getFormMap(OrderperFormMap.class);
			List<Map<String, Object>> orderperFormMaps=orderpreMapper.getByPage(orderperFormMap);
			LuogicPaging(pageNow, pageSize, orderperFormMaps);
			return pageView;
		}
		
		//预排3天分页。
				@ResponseBody
				@RequestMapping("walkthroughThree_findByPage")
				@Transactional(readOnly=false)
				public PageView walkthroughThree_findByPage(String pageNow, String pageSize) throws Exception 
				{	
					PublicUtils.Walkthrough_days=3;
					walkthrough();
					OrderperFormMap orderperFormMap=getFormMap(OrderperFormMap.class);
					List<Map<String, Object>> orderperFormMaps=orderpreMapper.getByPage(orderperFormMap);
					LuogicPaging(pageNow, pageSize, orderperFormMaps);
					return pageView;
				}
}
